package com.treeroot.smsservice.config;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @Description:
 * @Author:treeRoot
 * @Email:553503639@qq.com
 * @Date: Create in 23:42 / 2022/5/11
 */
@Configuration
public class TencentSmsConfig {
    /**
     * API相关
     */
    private static String URL ="sms.tencentcloudapi.com";
    private static final String REGION = "ap-guangzhou";
    /**
     * 账号相关
     */
    @Value("${tencent.sms.account.secret_id}")
    private String SECRET_ID;
    @Value("${tencent.sms.account.secret_key}")
    private String SECRET_KEY;


    @Bean
    public SmsClient smsClient(){
        // 实例化一个认证对象，入参需要传入腾讯云账户secretId，secretKey,
        Credential cred = new Credential(SECRET_ID, SECRET_KEY);
        // 实例化一个http选项，可选的，没有特殊需求可以跳过
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(URL);
        // 实例化一个client选项，可选的，没有特殊需求可以跳过
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        //实例化 SMS 的 client 对象
        return new SmsClient(cred, REGION, clientProfile);
    }
}

